//
//  ScoreTableViewCell.swift
//  SchoolDemo
//
//  Created by rimi on 16/10/10.
//  Copyright © 2016年 YQ. All rights reserved.
//

import UIKit

class ScoreTableViewCell: UITableViewCell {

    //科目title
    var scoretitleL = UILabel()
    //科目名
    var scoreNameBtn = UIButton()
    //老师名字
    var scoreTeacherL = UILabel()
    //时间
    var scoreTimeL = UILabel()
    //右侧成绩圆圈图
    var scoreView = UIImageView()
    //分数
    var scoreNumberL = UILabel()
    //合格与不合格
    var qualifiedL = UILabel()
    
    //下方View
    var teacherV = UIView()
    
    //老师评语
    var teacherRemarL = UILabel()
    //内容评语
    var messageRemarL = UILabel()
    //上分割线
    var TopLineView = UIView()
    //下分割线
    var BottomLineView = UIView()
    
     var cellHeight:CGFloat = 80
     var models:HSScoreModal?
    var model:HSScoreModal?{
        set{
            models = newValue
            if models?.cellIsSelected == false {
                cellHeight = 80
                TopLineView.isHidden = false
                BottomLineView.isHidden = true
                teacherRemarL.isHidden = true
                messageRemarL.isHidden = true
                teacherV.isHidden = true
            } else {
                cellHeight = 150
                TopLineView.isHidden = true
                BottomLineView.isHidden = false
                teacherRemarL.isHidden = false
                messageRemarL.isHidden = false
                teacherV.isHidden = false
            }
            
        }
        get{
            return models
        }
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI() {
        
        //科目title
        scoretitleL.textColor = UIColor().colorWithHex(0x4c4c4c)
        addSubview(scoretitleL)
        scoretitleL.snp.makeConstraints { (make) in
            make.top.equalTo(16)
            make.left.equalTo(16)
            make.width.equalTo(150)
            make.height.equalTo(33)
        }
        //科目
        scoreNameBtn.isUserInteractionEnabled = false
        scoreNameBtn.layer.cornerRadius = 10
        scoreNameBtn.layer.borderWidth = 1
        scoreNameBtn.setTitleColor(UIColor().colorWithHex(0x009ee7), for: UIControlState.normal)
        scoreNameBtn.layer.borderColor = UIColor().colorWithHex(0x009ee7).cgColor
        scoreNameBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        addSubview(scoreNameBtn)
        
        scoreNameBtn.snp.makeConstraints { (make) in
            make.left.equalTo(scoretitleL.snp.left)
            make.top.equalTo(scoretitleL.snp.bottom).offset(9)
            make.width.equalTo(44)
            make.height.equalTo(25)
        }
        //老师名字
        scoreTeacherL.font = UIFont.systemFont(ofSize: 14)
        scoreTeacherL.textColor = UIColor().colorWithHex(0x4c4c4c)
        scoreTeacherL.textAlignment = .right
        addSubview(scoreTeacherL)
        
        scoreTeacherL.snp.makeConstraints { (make) in
            make.top.equalTo(16)
            make.left.equalTo(scoretitleL.snp.right).offset(40)
            make.width.equalTo(70)
            make.height.equalTo(33)
            
        }
        //时间
        scoreTimeL.textAlignment = .center
        scoreTimeL.font = UIFont.systemFont(ofSize: 14)
        scoreTimeL.textColor = UIColor().colorWithHex(0x4c4c4c)
        addSubview(scoreTimeL)
        
        scoreTimeL.snp.makeConstraints { (make) in
            make.top.equalTo(scoreTeacherL.snp.bottom).offset(16)
            make.right.equalTo(scoreTeacherL.snp.right)
            make.bottom.equalTo(scoreNameBtn.snp.bottom)
            
        }
        //分数 合格 圆圈
        scoreNumberL.font = UIFont.systemFont(ofSize: 16)
        scoreNumberL.textColor = UIColor.white
        scoreView.addSubview(scoreNumberL)
        
        qualifiedL.textColor = UIColor.white
        qualifiedL.font = UIFont.systemFont(ofSize: 13)
        scoreView.addSubview(qualifiedL)
        
        scoreView.layer.cornerRadius = 20
        addSubview(scoreView)
        
        scoreView.snp.makeConstraints { (make) in
            make.top.equalTo(scoreTeacherL.snp.top)
            make.left.equalTo(scoreTeacherL.snp.right).offset(25)
            make.width.equalTo(65)
            make.height.equalTo(65)
            
        }
        scoreNumberL.snp.makeConstraints { (make) in
            make.top.equalTo(12)
            make.centerX.equalTo(scoreView.snp.centerX)
            make.height.equalTo(20)
        }
        qualifiedL.snp.makeConstraints { (make) in
            make.top.equalTo(scoreNumberL.snp.bottom).offset(6)
            make.centerX.equalTo(scoreView.snp.centerX)
            make.height.equalTo(10)
        }
        addSubview(teacherV)
        //内容评语
        messageRemarL.textColor = UIColor().colorWithHex(0x4c4c4c)
        messageRemarL.font = UIFont.systemFont(ofSize: 14)
        teacherV.addSubview(messageRemarL)
        //老师评语标题
        teacherRemarL.text = "老师评语:"
        teacherRemarL.textColor = UIColor().colorWithHex(0xd60a82)
        teacherRemarL.font = UIFont.systemFont(ofSize: 14)
        teacherV.addSubview(teacherRemarL)
        //下方View
        teacherV.backgroundColor = #colorLiteral(red: 0.9531012177, green: 0.9531235099, blue: 0.9531114697, alpha: 1)
        
        teacherV.snp.makeConstraints { (make) in
            make.top.equalTo(scoreTimeL.snp.bottom).offset(6)
            make.left.equalTo(scoreNameBtn.snp.left)
            make.right.equalTo(scoreView.snp.right)
            make.height.equalTo(44)
        }
      
        //老师评语坐标
        teacherRemarL.snp.makeConstraints { (make) in
            make.top.equalTo(3)
            make.left.equalTo(4)
            make.width.equalTo(150)
            make.height.equalTo(33)
        }
        //评语内容坐标
        messageRemarL.snp.makeConstraints { (make) in
            make.left.equalTo(teacherRemarL.snp.right).offset(5)
            make.top.equalTo(teacherRemarL.snp.top)
            make.height.equalTo(33)
            make.width.equalTo(250)
        }
        //上分割线
        TopLineView.backgroundColor = UIColor().colorWithHex(0x4c4c4c)
        addSubview(TopLineView)
        TopLineView.snp.makeConstraints { (make) in
            make.top.equalTo(scoreTimeL.snp.bottom).offset(5)
            make.left.equalTo(scoreNameBtn.snp.left)
            make.right.equalTo(scoreView.snp.right)
            make.height.equalTo(1)
            
        }
        //下方分割线
        BottomLineView.backgroundColor = UIColor().colorWithHex(0x4c4c4c)
        BottomLineView.isHidden = true
        addSubview(BottomLineView)
        
        BottomLineView.snp.makeConstraints { (make) in
            make.top.equalTo(teacherV.snp.bottom).offset(1)
            make.left.equalTo(TopLineView.snp.left)
            make.right.equalTo(TopLineView.snp.right)
            make.height.equalTo(1)
        }
    }
}
